/*
 * Ellipse.h
 *
 *      Author: Jerome RD Soine and Christoph A Brand
 *      Institution: Schwarz goup, Institute for Theoretical Physics, Heidelberg University, Germany
 */

#ifndef ELLIPSE_H_
#define ELLIPSE_H_

#include "Shape.h"
#include <vector>
#include <string>
#include <cmath>

using namespace std;

#ifndef M_PI
#define M_PI    3.14159265358979323846f
#endif

/*!
 *  \brief Ellipse shape object class
 *
 */

class Ellipse : public Shape
{
public:
	/*!
	 * Creates a Ellipse object with given center, orientation angle with x axis, major half-axis length  and
	 * minor half-axis length.
	 */
	Ellipse(vector<double> CENTER, double ORIENTATION_ANGLE, double A, double B)
	{center = CENTER; orientation_angle=ORIENTATION_ANGLE; a = A; b=B;};
	/*!
	 * Returns true if point is located within the Ellipse.
	 */
	bool is_on_shape(vector<double> point);
	/*!
	 * Returns ellipse area.
	 */
	double get_area(){return M_PI*a*b;}
	/*!
	 * Returns ellipse center.
	 */
	vector<double> get_center() {return center;};
	/*!
	 * Sets ellipse center.
	 */
	void set_center(vector<double> c) {center=c;};
	/*!
	 * Static function that returns a vector of Ellipse object pointers
	 * that has been loaded from tab-separated file: x_pos <TAB> x_pos <TAB> angle <TAB> major <TAB> minor.
	 */
	static vector<Shape*> get_shapes_from_file(string filename);
	/*!
	 * Returns distance to ellipse border in the direction to the center of the ellipse.
	 */
	double get_approximate_distance(vector<double> point);
	/*!
	 * Returns orientation angle with x axis.
	 */
	double get_orientation_angle();
	/*!
	 * Returns semi-major axis.
	 */
	double get_semi_major_axis();
	/*!
	 * Returns semi-minor axis.
	 */
	double get_semi_minor_axis();
	/*!
	 * Returns eccentricity
	 */
	double get_eccentricity() { return sqrt(1-b*b/(a*a)); };
	/*!
	 * Returns linear eccentricity
	 */
	double get_linear_eccentricity() { return sqrt(a*a-b*b); };
	/*!
	 * Returns length radius of a circle with same area
	 */
    double get_radius(){return sqrt(a*b);};

protected:
	/*!
		 * Major half axis length.
		 */
		double a;
		/*!
		 * Minor half axis length.
		 */
		double b;
	/*!
	 * Rotates point by angle around the center of the coordinate system and returns the new position.
	 */
	vector<double> rotate(vector<double> &point, double angle);
	/*!
	 * Center position of the Ellipse
	 */
	vector<double> center;
	/*!
	 * Orientation angle of the Ellipse with respect to x axis of cartesian coordinates
	 */
	double orientation_angle;
	/*!
	 * Flips angle according when ellipse orientation is given in pixel frame (y-axis pointing downwards).
	 */
	static double flip_orientation(double angle);

};


#endif /* ELLIPSE_H_ */
